<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//用户提现订单表
class Withdraw_order_model extends CI_Model{
    function __construct() {
        parent::__construct();
        $this->table = 'withdraw_order';
        $this->users = 'users';
        $this->users_info = 'users_info';
    }
    
    function get($where){
        return $this->db->select('*')->from($this->table)->where($where)->order_by('create_time desc')->get()->row_array();
    }
    
    function get_count($where){
        $this->db->select('*');
        $this->db->from($this->table);
        $this->db->where($where);
        $this->db->order_by('create_time','desc');
        $query = $this->db->get();
        return $query->num_rows();
    }
    
    function get_list($where){
        return $this->db->select('*')->from($this->table)->where($where)->order_by('create_time desc')->get()->result_array();
    }
    
    function getCount($where){
        $this->db->select('*');
        $this->db->from($this->table);
        $this->db->where($where);
        $this->db->order_by('create_time','desc');
        $query = $this->db->get();
        return $query->num_rows();
    }
    
    
    function getList($where,$page,$limit){
        $this->db->select($this->table.".*");
        $this->db->from($this->table);
        $this->db->where($where);
        $this->db->order_by('create_time','desc');
        $this->db->limit($limit, $page);
        return $this->db->get()->result_array();
    }
    
    function getTotal($where){
        $this->db->select('SUM(amount) amount');
        $this->db->from($this->table);
        $this->db->where($where);
        $this->db->order_by('id','desc');
        $result = $this->db->get()->row_array();
        return $result['amount'];
    }
    
    function insert($data){
        $this->db->insert($this->table, $data);
        if($this->db->affected_rows()){
            return $this->db->insert_id();
        }else{
            return 0;
        }
    }
    
    function update($data,$id){
        return $this->db->where('id',$id)->update($this->table, $data);
    }
    
    
    function delete($where){
        $this->db->where($where);
        $this->db->delete($this->table);
        return $this->db->affected_rows();
    }
    
    //首页调用
    function getListIndex($where,$page,$limit){
        $this->db->select($this->table.".user_id,".$this->table.".amount,".$this->table.".create_time,".$this->users.".username,".$this->users.'.vip_degree,'.$this->users_info.".nickname,".$this->users_info.".head_small_img");
        $this->db->from($this->table);
        $this->db->join($this->users, $this->users.'.user_id = '.$this->table.'.user_id', 'left');
        $this->db->join($this->users_info, $this->users_info.'.user_id = '.$this->table.'.user_id', 'left');
        $this->db->where($where);
        $this->db->order_by('create_time','desc');
        $this->db->limit($limit, $page);
        return $this->db->get()->result_array();
    }
    
}
